{S:X;X;0;0;Arrays \– Part 1{ITR-X}by Gerald L Fitton}
{S:X;X;0;1;Keywords:{ITT-X}Array Range Fitton}
{S:X;X;0;2;The directory Array01 is the first on this disc because the word \“Array\” starts with \“A\”, the first letter of the alphabet. However, the exercises in this directory are probably not the best ones to study first. Indeed, I suggest that the first file you look at is the [ZIntro] file in the directory Contents because it contains information about the contents of each of the directories on this disc.}
{S:X;X;0;3;If you are completely new to Wordz, Resultz or Fireworkz, and particularly if you have both Wordz and Resultz but not Fireworkz, then I suggest that, at an early stage, you read the [ReadMe] file in the Documents directory.}
{S:X;X;0;4;The files in this directory are intended to help you to understand an advanced feature of Resultz called Arrays. You may find it beneficial to study the tutorials in the Sheets series before those in the Array series since Sheets illustrate more fundamental features.}
{S:X;X;0;5;What is a Range?{ITR-X}{ITR-X}Load the file [Array01] from this directory and you will see that I have entered the ten numbers 1 to 10 into the rectangular block of slots stretching from b2 to c6. This set of slots is called a \“Range\”. If we were using a different spreadsheet package we might have to address each of these slots individually but in Resultz we can treat the range as a single entity. Resultz also supports the use of Names for variables\—see the tutorial in the Names01 directory on this disc\—and we can give a range such as b2c6 a variable name and then we can operate on the named range with an array function. More of this later.}
{S:X;X;0;6;Transferring Values from a Range to a Single Slot{ITR-X}{ITR-X} Rather than embarking upon an explanation of Names, let me show you how easy it is to load the whole range of ten values from the range b2c6 into the single slot, b10. Resultz saves the \‘input focus\’ along with the sheet so, unless I\’ve made a mistake (or unless you\’ve altered it) the \‘input focus\’ of [Array01] will be slot b10. An outline (black rather than grey) rectangle should surround the slot b10. If this is not the case then place the pointer \‘in\’ slot b10 and click the mouse select (left) button to select it. Look at the formula line (near the top of the spreadsheet just to the right of the cross and tick buttons). In it you will see b2c6. This is the simple formula which \‘stores\’ the range b2c6 in the single slot b10.}
{S:X;X;0;7;Taking a Snapshot of a Single Slot{ITR-X}{ITR-X}Now you might not believe that all ten values from b2c6 are stored in the one slot b10 because the only character which shows in the main body of the sheet (and all that would be printed) is the 1 from slot b2. Let me try to convince you that they are all there.}
{S:X;X;0;8;Place the pointer \‘in\’ slot b10, press and hold down the select button until the slot is \‘highlighted\’ in \‘inverse video\’ (ie it goes black). Click the menu (middle) button. Run the pointer through Edit, a sub menu opens, run the pointer through Make and click (select) on the option Make constant. Look in the formula line and you will see \{1,6\\\;2,7\\\;3,8\\\;4,9\\\;5,10\}, the full array. If you were to alter a value in the range b2c6 now it would not affect the \‘snapshotted\’ array in slot b10. Don\’t do it now\\\; you can give it a try later.}
{S:X;X;0;9;Entering the Formula{ITR-X}{ITR-X}Now to put it all back the way it was! With the full array in the formula line, place the pointer in the formula line and click select. Now execute <Ctrl U> (hold down the <Ctrl> button and tap the U key) to delete the array. Place the pointer in slot b2, press and hold down the select button and, still holding down the select button, move the pointer into slot c6, then release the select button. In future I shall refer to this operation as \‘dragging\’ from b2 to c6 or \‘selecting the range b2c6\’. Follow this selection process by clicking on the green tick (or tapping <Return>. The formula b2c6 will appear in the formula line (and the 1 remains in slot b10).}
{S:X;X;0;10;As an alternative to the technique of selecting the range b2c6 by dragging you can type b2c6 into the formula line. If you use this second method then you do not need to delete the array from the formula line because, as you type b2c6 it will \‘overwrite\’ the array.}
{S:X;X;0;11;Transferring an Array from a Slot to a Range{ITR-X}{ITR-X}The function set_value(,) is the easiest way I have found of transferring an array from a single slot to a range\\\; I have used this method in slot b12. The syntax of set_value(,) is set_value(to,from). Generally \“to\” and \“from\” are slot references but, if \“to\” is a range and \“from\” is the slot containing an array, then as much as possible of the array as will fit the range is transferred to the range.}
{S:X;X;0;12;Recovering a Single Value from an Array{ITR-X}{ITR-X}Sometimes you may want to recover only one value from an array. I believe that the index function is the easiest way of doing this. Click on slot b20 and you will see that I have used the index function to recover the value from column 2, row 4 of the array. The syntax is index(array,col,row) where \“array\” is the array to be interrogated (we are using the array in slot b10), \“col\” is the column in the array (we want the second of the two columns so we use 2) and \“row\” is the row of the array (we want the fourth row of six so we use 4) giving us index(b10,2,4) as our entry in slot b20.}
{S:X;X;0;13;The index function in its extended form, index(array,col,row,cols,rows), can be used to recover more than one value from an array. The result returned is a (smaller) array in a single slot containing the index function. Again, more of this in a later article.}
{S:X;X;0;14;Over to You{ITR-X}{ITR-X}You can experiment yourself by loading the file [Array01z]. You should find that the \‘input focus\’ is positioned in slot b10. If it isn\’t there (because I\’ve made a mistake when I saved the file) then place the pointer \‘in\’ slot b10 and click select. Enter the formula b2c6 into the formula line and either click on the green tick or tap <Return>.}
{S:X;X;0;15;Experiment with this spreadsheet. You can insert an additional row into the range b2c6 by tapping <F7> however, if you do insert a row then beware that I have not written the formula in slot b12 (for recovering the array) in its most \‘general\’ form. Because of this you will have to alter the space allocated to the output range by inserting a row somewhere between row 12 and row 16 with <F7> to match the extra row you have inserted between rows 2 and 6. You can insert a column between b and c using <Shift F7> with impunity!}